import {
    getSetting
} from '@/api/setting'
import {
    siteTitle,
} from "@/utils"
export default {
    namespaced: true,
    state: {
        loading: false,
        data: [],
    },
    mutations: {
        changeLoading(state, payload) {
            state.loading = payload;
        },
        getData(state, payload) {
            state.data = payload
        }
    },
    actions: {
        async fetchData(cxt) {
            cxt.commit("changeLoading", true);
            const resp = await getSetting();
            cxt.commit("getData", resp);
            cxt.commit("changeLoading", false);
            if (resp.siteTitle) {
                siteTitle.setSiteTitle(resp.siteTitle)
            }
            if (resp.favicon) {
                let link = document.querySelector('link[rel="icon"]');
                if (link.href = resp.favicon) {
                    return;
                }
                link.href = resp.favicon;
            }
        }
    }
}